import numpy as np


# 新建 array
np.array
np.ones
np.zeros
np.random
np.random.uniform(size=(2, 2))
# array运算
ndary = np.array([[i for i in range(10)] for j in range(10)])
# 四则  % // 复合 += -= *= /=
ndary = ndary + 1
ndary = ndary - 1
ndary = ndary * 2
ndary = ndary / 2
# 其他
ndsqr = ndary ** 2
ndSum = sum(ndary)
ndSum = ndary.sum(axis=0)
ndSum = ndary.sum(axis=1)
ndary += ndary
# 切片、编辑
ndary[:2, 3]  # 前两行  第三列
ndary[::2, 4:]  # 偶数列 第四列
# 基本的矩阵运算
np.dot         # 点积
np.cross       # 叉积
ndary * ndary  # 矩阵 * 矩阵
np.linalg.inv  # 求逆
ndary.T        # 转置

# 数据保存、读入
ndary.dumps           # np.loads
ndary.tofile          # np.fromfile
np.save               # np.load
np.savez              # np.load
np.savez_compressed   # np.load
np.savetxt            # np.loadtxt


np.save("data.npy", arr=ndary)
np.savez("data.npz", x=ndary, y=ndary)
npzfile = np.load("data.npz")
npzfile["x"]  # 和保存的一致
npzfile["y"]  #
